package com.study.design.pattern.pattern.behavioral.mediator;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: gongsl
 * @Date: 2025-03-25 21:44
 * @description: 具体中介者
 */
public class ChatRoom implements ChatMediator {

    private final List<User> users = new ArrayList<>();

    @Override
    public void addUser(User user) {
        users.add(user);
    }

    @Override
    public void sendMessage(String message, User sender) {
        for (User user : users) {
            // 不给自己发消息
            if (user != sender) {
                user.receiveMessage(message);
            }
        }
    }
}
